package ink.mint.convolution;

import ink.mint.loss.LossType;
import ink.mint.neural.Layer;
import ink.mint.neural.MultiLayerConfiguration;
import ink.mint.neural.NeuralNetwork;
import ink.mint.parameter.Parameter;

import java.io.IOException;
import java.util.List;

public class ConvolutionLayerConfiguration {
    double[][][] X;
    double[] Y;
    ConvolutionNeuralNetwork cnn;

    Parameter parameter;

    public ConvolutionLayerConfiguration(double[][][] X, double[] Y) {
        this.X = X;
        this.Y = Y;
        cnn = new ConvolutionNeuralNetwork();
        cnn.input(X);
        cnn.setY(Y);
    }

    public ConvolutionLayerConfiguration saveParameter(String ParameterFullFileNamePath) {
        this.parameter = new Parameter(ParameterFullFileNamePath);
        return this;
    }

    public ConvolutionLayerConfiguration readParameter(String ParameterFullFileNamePath) throws IOException, ClassNotFoundException {
        this.parameter = new Parameter(ParameterFullFileNamePath);
        ConvolutionNeuralNetwork convolutionNeuralNetwork = parameter.deConvolutionLayerSerialize();
        cnn.setConvolutionLayerList(convolutionNeuralNetwork.getConvolutionLayerList());
        cnn.getNeuralNetwork().setLayerList(convolutionNeuralNetwork.getNeuralNetwork().getLayerList());
        return this;
    }

    public ConvolutionLayerConfiguration convolutionLayerConfiguration(ConvolutionLayer layer) {
        cnn.addConvolutionLayer(layer);
        return this;
    }

    public ConvolutionLayerConfiguration fullyConnectedLayerConfiguration(Layer layer) {
        cnn.addFullyConnectedLayer(layer);
        return this;
    }

    public ConvolutionLayerConfiguration lossConfiguration(LossType lossType) {
        cnn.setLossType(lossType);
        return this;
    }

    public ConvolutionLayerConfiguration learningRateConfiguration(double learningRate) {
        cnn.setLearningRate(learningRate);
        return this;
    }

    public ConvolutionLayerConfiguration train() {
        cnn.train();
        parameter.convolutionSerialize(cnn);
        return this;
    }

    public ConvolutionLayerConfiguration run() {
        cnn.run();
        return this;
    }
}
